package com.leo.customer.entity.pojo

import com.leo.customer.entity.CreateTimeAndUpdateTime
import java.time.LocalDateTime
import javax.persistence.*
import javax.validation.constraints.NotBlank

@Entity
data class AccessoryPlan(
        /**
         * 所属组织
         */
        @ManyToOne(targetEntity = Organize::class, cascade = [CascadeType.PERSIST, CascadeType.MERGE], fetch = FetchType.LAZY)
        @JoinColumn(name = "organize_id")
        var organize: Organize = Organize(),
        @field:NotBlank(message = "计划名称不能为空")
        var planName: String = "",
        var planShare: Float = 10F,
        var planNeed: String = "{}",
        var expireDate: LocalDateTime = LocalDateTime.now()
) : CreateTimeAndUpdateTime()

data class AccessoryPlanVo(
        var id: Int,
        var organize: Organize,
        var planName: String,
        var planNeed: MutableList<String>,
        var planShare: Float,
        var expireDate: LocalDateTime
) {
    fun convert(): AccessoryPlan {
        val accessoryPlan = AccessoryPlan()
        accessoryPlan.organize = organize
        accessoryPlan.planName = planName
        accessoryPlan.planShare = planShare
        accessoryPlan.expireDate = expireDate
        accessoryPlan.planNeed = planNeed.toString()
        return accessoryPlan
    }
}
